﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using SoftwareConsulting.BI11.Studio.InternalServices;
using SoftwareConsulting.BI11.Studio.Core.Project.Metadata;
using SoftwareConsulting.BI11.Studio.UI.Properties;
using SoftwareConsulting.BI11.NumericalMethods;

namespace SoftwareConsulting.BI11.Studio.UI.ProjectExplorer.ClassificationProblems
{
    public partial class ClassificationProblemWithTrainingSetCorrectClassDialog : RestorableForm
    {
        private int _correctClass;//корректный класс
        private IClassificationProblemWithTraining _problem; //задача классификации с обучением

        /// <summary>
        /// Возвращает корректный класс
        /// </summary>
        public int CorrectClass
        {
            get
            {
                return _correctClass;
            }
        }

        /// <summary>
        /// Инициализирует диалог
        /// </summary>
        private void Initialize()
        {            
            var classes = _problem.ClassesNames;
            var attributes = _problem.AttributesNames;
            if ((classes == null) || (classes.GetIndicatorValuesCount() == 1))//1, т.к. 0й - [не важно]
            {
                OKButton.Enabled = false;
                return;
            }            
            var classItems = CorrectClassBox.Properties.Items;
            classItems.Clear();
            for (int i = 1; i < classes.GetIndicatorValuesCount(); i++)//с первого, т.к. 0й - [не важно]
            {
                classItems.Add(classes.GetIndicatorValueByPosition(i).Value as string);
            }
            CorrectClassBox.SelectedIndex = 0;
            _correctClass = 0;
        }

        /// <summary>
        /// Применяет изменения и закрывает диалог
        /// </summary>
        private void ApplyAndClose()
        {
            _correctClass = CorrectClassBox.SelectedIndex;
            DialogResult = DialogResult.OK;
            Close();
        }

        /// <summary>
        /// Отменяет изменения и закрывает диалог
        /// </summary>
        private void CancelAndClose()
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        public ClassificationProblemWithTrainingSetCorrectClassDialog(IClassificationProblemWithTraining problem)
        {
            _problem = problem;            
            InitializeComponent();
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            ApplyAndClose();
        }

        private void CancelCorrectClassButton_Click(object sender, EventArgs e)
        {
            CancelAndClose();
        }

        private void ClassificationProblemWithTrainingSetCorrectClassDialog_Load(object sender, EventArgs e)
        {
            Initialize();
        }        
    }
}
